package com.mail;



import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class Application extends Activity implements Runnable{
	/** Called when the activity is first created. */
	EditText et_to;
	EditText et_gps;
	EditText et_barcode;
	ProgressDialog progressDialog;
	Thread thread;
	String info;
	LocationManager mlocManager=null;
	 LocationListener mlocListener;
	 AlertDialog.Builder alert;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		alert  = new AlertDialog.Builder(this);
		 alert.setCancelable(true);
		 et_gps=(EditText)findViewById(R.id.et_gps);

	    mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        mlocListener = new MyLocationListener();	        
        mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
        mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
	        
	     Button btn_gps=(Button)findViewById(R.id.btn_gps);
	     btn_gps.setOnClickListener(new View.OnClickListener() {        
	            @Override
	            public void onClick(View view) {
	            	
			        
			        mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
			        
			       

			        if (mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
			        	if(MyLocationListener.latitude>0)
			        	{
			        	et_gps.setText("Latitude:- " + MyLocationListener.latitude
		                        + '\n');
			        	et_gps.append("Longitude:- " + MyLocationListener.longitude);
			        	
			        	//Shuts off the gps after it fetches it
			        	mlocManager.removeUpdates(mlocListener); 
			        	mlocManager = null;
			        	}
			        	else
			        	{
			        		alert.setTitle("GPS");
							alert.setMessage("GPS activation in progress,\n Please click after few second.");
							alert.setPositiveButton("OK", null);
							alert.show();
							
			        	}
		               
			        } else {
			        	alert.setTitle("GPS");
						alert.setMessage("GPS is not turned on...");
						alert.setPositiveButton("OK", null);
						alert.show();
			        }
	            }
	        }); 
	     
	}
	
	public void run() {
		handler.sendEmptyMessage(0);		
	}
	private Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
		}
	};
}